<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>调色板</title>
        <style>
            .color-container{
                width: 400px;
                min-height: 400px;
                border:solid 1px #666;
                margin: 100px auto;
            }

            .color-show{
                width: 100%;
                height: 250px;
                background: #ccc;
            }

            .color-control{
                padding: 10px 20px;
            }
        </style>
    </head>
    <body>
        <div id="root"></div>

        <script src="../js/react.development.js"></script>
        <script src="../js/react-dom.development.js"></script>
        <script src="../js/babel.min.js"></script>

        <script type="text/babel">
            class App extends React.Component {

                state = {
                    r: 0,
                    g: 0,
                    b: 0
                }

                render() {
                    let {r, g, b} = this.state;
                    return (
                        <div className="color-container">
                            <div className="color-show" style={{background: `rgb(${r}, ${g}, ${b})`}}>
                                
                            </div>
                            <hr />
                            <div className="color-control">
                                R <input type="range" min="0" name="r"  max="255" value={r} onChange={this.change} /><br />
                                G <input type="range" min="0" name="g"  max="255" value={g} onChange={this.change} /><br />
                                B <input type="range" min="0" name="b"  max="255" value={b} onChange={this.change} /><br />
                                <div>{`rgb(${r}, ${g}, ${b})`} </div>
                            </div>
                        </div>
                    );
                }

                change = (e) => {
                    this.setState({
                        [e.target.name]: e.target.value
                    })
                }
            }
            
            ReactDOM.render(<App />, document.querySelector("#root"));
        </script>
    </body>
</html>
